package com.dayu.web.controller.recovery;

import java.util.List;

import com.dayu.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.recovery.domain.RecoveryParts;
import com.dayu.recovery.service.IRecoveryPartsService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 配件管理Controller
 *
 * @author HK
 * @date 2021-04-16
 */
@RestController
@RequestMapping("/recovery/parts")
public class RecoveryPartsController extends BaseController
{
    @Resource
    private IRecoveryPartsService recoveryPartsService;

    /**
     * 查询配件管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RecoveryParts recoveryParts)
    {
        startPage();
        List<RecoveryParts> list = recoveryPartsService.selectRecoveryPartsList(recoveryParts);
        return getDataTable(list);
    }

    /**
     * 导出配件管理列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:parts:export')")
    @Log(title = "配件管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RecoveryParts recoveryParts)
    {
        List<RecoveryParts> list = recoveryPartsService.selectRecoveryPartsList(recoveryParts);
        ExcelUtil<RecoveryParts> util = new ExcelUtil<RecoveryParts>(RecoveryParts.class);
        return util.exportExcel(list, "parts");
    }

    /**
     * 获取配件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:parts:query')")
    @GetMapping(value = "/{partsId}")
    public AjaxResult getInfo(@PathVariable("partsId") Long partsId)
    {
        return AjaxResult.success(recoveryPartsService.selectRecoveryPartsById(partsId));
    }

    /**
     * 新增配件管理
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('recovery:parts:add')")
    @Log(title = "配件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecoveryParts recoveryParts)
    {
        return toAjax(recoveryPartsService.insertRecoveryParts(recoveryParts));
    }

    /**
     * 修改配件管理
     */
    @PreAuthorize("@ss.hasPermi('recovery:parts:edit')")
    @Log(title = "配件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecoveryParts recoveryParts)
    {
        return toAjax(recoveryPartsService.updateRecoveryParts(recoveryParts));
    }

    /**
     * 删除配件管理
     */
    @PreAuthorize("@ss.hasPermi('recovery:parts:remove')")
    @Log(title = "配件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partsIds}")
    public AjaxResult remove(@PathVariable Long[] partsIds)
    {
        return toAjax(recoveryPartsService.deleteRecoveryPartsByIds(partsIds));
    }
}
